#pragma once

#include <iostream>
#include <string>

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include "../comm/log.hpp"
#include "../comm/util.hpp"

namespace dsh_runner
{
    using namespace dsh_log;
    using namespace dsh_util;

    class Runner
    {
    public:
        Runner(){}
        ~Runner(){}
    public:
        static int Run(const std::string& file_name)
        {
            std::string _execute = PathUtil::Exe(file_name);
            std::string _stdin   = PathUtil::Stdin(file_name);
            std::string _stdout  = PathUtil::Stdout(file_name);
            std::string _stderr  = PathUtil::Stderr(file_name);

            umask(0);
            int _stdin_fd  = open(_stdin.c_str(), O_CREAT | O_WRONLY, 0644);
            int _stdout_fd = open(_stdout.c_str(), O_CREAT | O_RDONLY, 0644);
            int _stderr_fd = open(_stderr.c_str(), O_CREAT | O_RDONLY, 0644);

            pid_t pid = fork();
            if (pid < 0)
            {

            }
            else if (pid == 0)
            {
                // 子进程
            }
            else
            {

            }
        }
    };
}